/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName: VerifyUtil
 * @Description: 验证工具类
 * @author youjun
 * @date 2017年7月14日 下午2:12:09
 */
public class VerifyUtil {

	/**email*/
	public static final String EMAIL_REGULAR = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$";
	
	/**日期yyyy-MM-dd*/
	public static final String DATA_YYYY_MM_DD = "\\d{4}-\\d{2}-\\d{2}";
	
	/**
	 *@Title: isEmail
	 *@Description: 判断邮箱
	 *@return boolean
	 *@author youjun
	 *@date 2017年7月14日 下午2:14:02
	 *@param email
	 *@return
	 */
	public static boolean isEmail(final String email) {
		final Pattern p = Pattern.compile(EMAIL_REGULAR);
		final Matcher m = p.matcher(email);
		return m.matches();
	}

	/**
	 *@Title: isValidDate
	 *@Description: 判断日期格式:yyyy-mm-dd
	 *@return boolean
	 *@author youjun
	 *@date 2017年7月14日 下午2:14:15
	 *@param sDate
	 *@return
	 */
	public static boolean isValidDate(final String sDate) {
		final String datePattern = "^((\\d{2}(([02468][048])|([13579][26]))"
				+ "[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|"
				+ "(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?"
				+ "((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?("
				+ "(((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?"
				+ "((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
		if ((sDate != null)) {
			Pattern pattern = Pattern.compile(DATA_YYYY_MM_DD);
			Matcher match = pattern.matcher(sDate);
			if (match.matches()) {
				pattern = Pattern.compile(datePattern);
				match = pattern.matcher(sDate);
				return match.matches();
			} else {
				return false;
			}
		}
		return false;
	}
	
}
